package websimulator;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import calculations.Moduls;

import readwrite.Connector;

/**
 * Servlet implementation class NewModul
 */
@WebServlet("/NewModul")
public class NewModul extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private Connector con;
    /**
     * @throws Exception 
     * @see HttpServlet#HttpServlet()
     */
    public NewModul() throws Exception {
        super();
        con = new Connector();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 * Makes a new modul with the name you typed in the webpage.
	 * 
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		String name = request.getParameter("name");
		String answer="";
		try {
				con.newModul(name);
				answer = "<input type=\"hidden\" name=\"id\" id=\"modulId\" value=\""+con.getModulId(name)+"\">";

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		response.setContentType("text/plain");
		response.getWriter().write(answer);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
